//
//  UITextViewViewController.swift
//  Example
//
//  Created by T AO on 2022/2/15.
//

import UIKit
import RxCocoa
import RxSwift

class UITextViewViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        textView()
    }

}

// MARK: - UITextView

extension UITextViewViewController {
    /// UITextView 还封装了如下几个委托回调方法：
    ///
    /// didBeginEditing：开始编辑
    /// didEndEditing：结束编辑
    /// didChange：编辑内容发生改变
    /// didChangeSelection：选中部分发生变化
    ///
    private func textView() {
        let textView = UITextView(frame: CGRect(x: 20, y: 300, width: 300, height: 100))
        textView.layer.borderWidth = 0.5
        textView.layer.borderColor = UIColor.gray.cgColor
        view.addSubview(textView)
        
        // 开始编辑响应
        textView.rx.didBeginEditing
            .subscribe(onNext: { print("开始编辑") })
            .disposed(by: disposeBag)
        
        textView.rx.didEndEditing
            .subscribe(onNext: { print("结束编辑") })
            .disposed(by: disposeBag)
        
        textView.rx.didChange
            .subscribe(onNext: { print("内容发生改变") })
            .disposed(by: disposeBag)
        
        // 选中部分变化响应
        textView.rx.didChangeSelection
            .subscribe(onNext: { print("选中部分发生变化") })
            .disposed(by: disposeBag)
        
    }
}

